<?php
namespace app\app\model;

use think\Model;
class Policy extends Model
{
	public function getPolicyList($keyword = '',$userId,$role){
		$result = array();
		if ($role == 'admin'){
			if ($keyword != '' && $keyword != false){
				$result = db('policy')->where('policy','like','%'.$keyword.'%')->where('if_publish','1')->paginate(10);
			}else {
				$result = db('policy')->where('if_publish','1')->paginate(10);
			}
			
		}else {
			$user_warehouse = db('ouser')->where('id',$userId)->value('warehouse_id');
			if ($keyword != '' && $keyword != false){
				$result = db('policy')->field(['id','policy','created'])->where('to_where','like','%"'.$user_warehouse.'"%')->where('policy','like','%'.$keyword.'%')->where('if_publish','1')->paginate(10);
			}else {
				$result = db('policy')->field(['id','policy','created'])->where('to_where','like','%"'.$user_warehouse.'"%')->where('policy','like','%'.$keyword.'%')->where('if_publish','1')->paginate(10);
			}
		}
		return $result;
	}
}
